import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login',
    component: Home,
    children: [
      // 发现音乐
      {
        path: '/DiscoverMusic',
        component: () => import('../components/DiscoverMusic/DiscoverMusic.vue')
      },
      // 视频
      {
        path: '/VideoCom',
        component: () => import('../components/VideoCom/VideoCom.vue')
      },
      // 朋友
      {
        path: '/FriendCom',
        component: () => import('../components/FriendCom/FriendCom.vue')
      },
      // 直播
      {
        path: '/LiveBroadcast',
        component: () => import('../components/LiveBroadcast/LiveBroadcast.vue')
      },
      // 私人FM
      {
        path: '/PrivateFM',
        component: () => import('../components/PrivateFM/PrivateFM.vue')
      },
      // 歌单详情
      {
        path: '/SongDetails',
        component: () => import('../components/SongDetails/SongDetails.vue')
      },
    ]
  },
  {
    path: '/login',
    component: () => import('../components/Login/Login.vue'),
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
// 重复点击路由报错解决方案
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default router
